<!-- HTML header for doxygen 1.9.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CMSIS-Core (Cortex-A): Using CMSIS in Embedded Applications</title>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="tabs.js"></script>
<script type="text/javascript" src="footer.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/javascript" src="darkmode_toggle.js"></script>
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
<link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
<link href="extra_search.css" rel="stylesheet" type="text/css"/>
<link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
<link href="version.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../version.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 55px;">
  <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
  <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
   <div id="projectname">CMSIS-Core (Cortex-A)
   &#160;<span id="projectnumber"><script type="text/javascript">
     <!--
     writeHeader.call(this);
     writeVersionDropdown.call(this, "CMSIS-Core (Cortex-A)");
     //-->
    </script>
   </span>
   </div>
   <div id="projectbrief">CMSIS-Core support for Cortex-A processor-based devices</div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
  <!--END !PROJECT_NAME-->
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
  <ul class="tablist">
    <script type="text/javascript">
      writeComponentTabs.call(this);
    </script>
  </ul>
</div>
<script type="text/javascript">
  writeSubComponentTabs.call(this);
</script>
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('using_pg.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">Using CMSIS in Embedded Applications </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="md_src_using"></a> To use the CMSIS-Core-A the following files are added to the embedded application:</p><ul>
<li><a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> with reset handler and exception vectors.</li>
<li><a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> with general device configuration (i.e. for clock and bus setup).</li>
<li><a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> gives access to processor core and all peripherals.</li>
<li><a class="el" href="mem_h_pg.html">Memory Configuration Files mem_&lt;device&gt;.h</a> contains basic memory configurations.</li>
<li><a class="el" href="mmu_c_pg.html">Memory Management Unit Files mmu_&lt;device&gt;.c</a> contains the memory management unit setup.</li>
</ul>
<blockquote class="doxtable">
<p>&zwj;<b>Note</b></p><ul>
<li>The files <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a>, <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a>, <a class="el" href="mem_h_pg.html">Memory Configuration Files mem_&lt;device&gt;.h</a>, and <a class="el" href="mmu_c_pg.html">Memory Management Unit Files mmu_&lt;device&gt;.c</a> may require application specific adaptations and therefore should be copied into the application project folder prior configuration. The <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> is included in all source files that need device access and can be stored on a central include folder that is generic for all projects. </li>
</ul>
</blockquote>
<p>The <code>Reset_Handler</code> defined in <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> is executed after reset. The default initialization sequence is</p><ul>
<li>set the vector base address register (<a class="el" href="group__CMSIS__VBAR.html#ga582f9a60f7b090ae5a4e8f60ef3b79f8">__set_VBAR</a>),</li>
<li>set stacks for each exception mode (<a class="el" href="group__CMSIS__Core__RegAccFunctions.html#ga7ad5710bc622794ffed1d31740f6be55">__set_mode</a>, <a class="el" href="group__CMSIS__Core__RegAccFunctions.html#ga6d25d5770874bf1c824f892739bfdf41">__set_SP</a>),</li>
<li>call <a class="el" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2">SystemInit</a>.</li>
</ul>
<p>After the system initialization control is transferred to the C/C++ run-time library which performs initialization and calls the <b>main</b> function in the user code. In addition the <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> contains a weak default handler implementation for every exception. It may also contain stack and heap configurations for the user application.</p>
<p>The <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> performs the setup for the processor clock and the initialization of memory caches, memory management unit, generic interrupt interface and floating point unit. The variable <a class="el" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> indicates the CPU clock speed. <a class="el" href="group__system__init__gr.html">System and Clock Configuration</a> describes the minimum feature set. In addition the file may contain functions for the memory bus setup and clock re-configuration.</p>
<p>The <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> is the central include file that the application programmer is using in the C/C++ source code. It provides the following features:</p><ul>
<li><a class="el" href="group__peripheral__gr.html">Peripheral Access</a> provides a standardized register layout for all peripherals. Optionally functions for device-specific peripherals may be available.</li>
<li><a class="el" href="group__GIC__functions.html">Generic Interrupt Controller Functions</a> can be accessed with standardized symbols and functions for the General Interrupt Controller (GIC) are provided.</li>
<li><a class="el" href="group__CMSIS__Core__InstructionInterface.html">Intrinsic Functions</a> allow to access special instructions, for example for activating sleep mode or the NOP instruction.</li>
<li><a class="el" href="group__PL1__timer__functions.html">Generic</a> and <a class="el" href="group__PTM__timer__functions.html">Private</a> Timer functions to configure and start a periodic timer interrupt.</li>
<li><a class="el" href="group__L1__cache__functions.html">Level 1</a> and <a class="el" href="group__L2__cache__functions.html">Level 2</a> Cache controller functions to enable, disable, clean and invalidate caches.</li>
</ul>
<p>The use of <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> can be abstracted with the <code>#define CMSIS_header_file</code> provided in <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/cp_Packs.html#cp_RTECompH">RTE_Components.h</a>. This allows to have uniform include code in the application independent of the target device.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span>                      <span class="comment">// include information about project configuration</span></div>
<div class="line"><span class="preprocessor">#include CMSIS_device_header                     </span><span class="comment">// include &lt;Device&gt;.h file</span></div>
</div><!-- fragment --><div class="image">
<img src="CMSIS_CORE_A_Files_user.png" alt=""/>
<div class="caption">
CMSIS-Core-A User Files</div></div>
    <p>The CMSIS-Core-A user files are device specific. In addition, the <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> is also compiler vendor specific. The various compiler vendor tool chains may provide folders that contain the CMSIS files for each supported device.</p>
<blockquote class="doxtable">
<p>&zwj;<b>Note</b></p><ul>
<li>The silicon vendors create these device-specific CMSIS-Core-A files based on <a class="el" href="templates_pg.html">CMSIS-Core Device Templates</a> provide by Arm. </li>
</ul>
</blockquote>
<p>Thereafter, the functions described under <a href="modules.html">API Reference</a> can be used in the application.</p>
<p><b>Examples:</b></p><ul>
<li><a class="el" href="using_pg.html#using_CMSIS">CMSIS Basic Example</a> is a simple example that shows the usage of the CMSIS layer.</li>
<li><a class="el" href="using_pg.html#using_ARM_pg">Using CMSIS with generic Arm Processors</a> explains how to use CMSIS-Core-M for Arm processors.</li>
</ul>
<h1><a class="anchor" id="using_CMSIS"></a>
CMSIS Basic Example</h1>
<p>A typical example for using the CMSIS layer is provided below. The example is based on an unspecific Cortex-A9 Device.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;ARMCA9.h&gt;</span>                              <span class="comment">// File name depends on device used</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keyword">const</span> uint32_t TICK_RATE_HZ = 1000U;</div>
<div class="line"> </div>
<div class="line">uint32_t <span class="keyword">volatile</span> msTicks;                       <span class="comment">// Counter for millisecond Interval</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> SysTick_Handler( <span class="keywordtype">void</span> )</div>
<div class="line">{</div>
<div class="line">  msTicks++;                                     <span class="comment">// Increment Counter</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.</span></div>
<div class="line"><span class="comment">// In general the available Timers are highly vendor specific for Cortex-A processors.</span></div>
<div class="line"><span class="keywordtype">void</span> private_timer_init(<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line">  <a class="code hl_function" href="group__PTM__timer__functions.html#ga30516fed24977be8eecf3efd8b6a2fea">PTIM_SetLoadValue</a> ((<a class="code hl_variable" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a>/TICK_RATE_HZ) - 1U);</div>
<div class="line">  <a class="code hl_function" href="group__PTM__timer__functions.html#gaabc1dba029389fe0e2a6297952df7972">PTIM_SetControl</a> (<a class="code hl_function" href="group__PTM__timer__functions.html#ga34f0ceea142a4be1479cb552bf8bc4d1">PTIM_GetControl</a>() | 7U);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Install SysTick_Handler as the interrupt function for PTIM */</span></div>
<div class="line">  <a class="code hl_function" href="group__irq__ctrl__gr.html#gac1fcc16fb8e488d315cfa496f1d71db3">IRQ_SetHandler</a>((<a class="code hl_typedef" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)PrivTimer_IRQn, SysTick_Handler);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Determine number of implemented priority bits */</span></div>
<div class="line">  <a class="code hl_function" href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a> ((<a class="code hl_typedef" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)PrivTimer_IRQn, <a class="code hl_define" href="group__irq__priority__defs.html#gabaa4e91ab84dbe5f669080af6d0d81fa">IRQ_PRIORITY_Msk</a>);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Set lowest priority -1 */</span></div>
<div class="line">  <a class="code hl_function" href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a> ((<a class="code hl_typedef" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)PrivTimer_IRQn, <a class="code hl_function" href="group__GIC__functions.html#ga397048004654f792649742f95bf8ae67">GIC_GetPriority</a>((<a class="code hl_typedef" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)PrivTimer_IRQn)-1);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Enable IRQ */</span></div>
<div class="line">  <a class="code hl_function" href="group__irq__ctrl__gr.html#ga4ad780a3dc23a1b6222de8adcd7c20a7">IRQ_Enable</a> ((<a class="code hl_typedef" href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a>)PrivTimer_IRQn);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/* Delay execution for given amount of ticks */</span></div>
<div class="line"><span class="keywordtype">void</span> Delay(uint32_t ticks)  {</div>
<div class="line">  uint32_t tgtTicks = msTicks + ticks;             <span class="comment">// target tick count to delay execution to</span></div>
<div class="line">  <span class="keywordflow">while</span> (msTicks == tgtTicks)  {</div>
<div class="line">    __WFE ();                                      <span class="comment">// Power-Down until next Event/Interrupt</span></div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/* main function */</span></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">  <span class="comment">/* Initialize device HAL here */</span></div>
<div class="line">  private_timer_init();</div>
<div class="line"> </div>
<div class="line">  <span class="keyword">static</span> uint8_t ledState = 0;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">/* Infinite loop */</span></div>
<div class="line">  <span class="keywordflow">while</span> (1)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">/* Add application code here */</span></div>
<div class="line">    ledState = !ledState;</div>
<div class="line">    Delay(500);</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="ttc" id="agroup__GIC__functions_html_ga397048004654f792649742f95bf8ae67"><div class="ttname"><a href="group__GIC__functions.html#ga397048004654f792649742f95bf8ae67">GIC_GetPriority</a></div><div class="ttdeci">__STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)</div><div class="ttdoc">Read the current interrupt priority from GIC's IPRIORITYR register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:1664</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_ga30516fed24977be8eecf3efd8b6a2fea"><div class="ttname"><a href="group__PTM__timer__functions.html#ga30516fed24977be8eecf3efd8b6a2fea">PTIM_SetLoadValue</a></div><div class="ttdeci">__STATIC_INLINE void PTIM_SetLoadValue(uint32_t value)</div><div class="ttdoc">Set the load value to timers LOAD register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:2009</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_ga34f0ceea142a4be1479cb552bf8bc4d1"><div class="ttname"><a href="group__PTM__timer__functions.html#ga34f0ceea142a4be1479cb552bf8bc4d1">PTIM_GetControl</a></div><div class="ttdeci">__STATIC_INLINE uint32_t PTIM_GetControl(void)</div><div class="ttdef"><b>Definition:</b> core_ca.h:2048</div></div>
<div class="ttc" id="agroup__PTM__timer__functions_html_gaabc1dba029389fe0e2a6297952df7972"><div class="ttname"><a href="group__PTM__timer__functions.html#gaabc1dba029389fe0e2a6297952df7972">PTIM_SetControl</a></div><div class="ttdeci">__STATIC_INLINE void PTIM_SetControl(uint32_t value)</div><div class="ttdoc">Configure the timer using its CONTROL register.</div><div class="ttdef"><b>Definition:</b> core_ca.h:2040</div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_ga4ad780a3dc23a1b6222de8adcd7c20a7"><div class="ttname"><a href="group__irq__ctrl__gr.html#ga4ad780a3dc23a1b6222de8adcd7c20a7">IRQ_Enable</a></div><div class="ttdeci">int32_t IRQ_Enable(IRQn_ID_t irqn)</div><div class="ttdoc">Enable interrupt.</div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_gaa90aed20ac94420fff4bbbf55c12d4c2"><div class="ttname"><a href="group__irq__ctrl__gr.html#gaa90aed20ac94420fff4bbbf55c12d4c2">IRQ_SetPriority</a></div><div class="ttdeci">int32_t IRQ_SetPriority(IRQn_ID_t irqn, uint32_t priority)</div><div class="ttdoc">Set interrupt priority value.</div></div>
<div class="ttc" id="agroup__irq__ctrl__gr_html_gac1fcc16fb8e488d315cfa496f1d71db3"><div class="ttname"><a href="group__irq__ctrl__gr.html#gac1fcc16fb8e488d315cfa496f1d71db3">IRQ_SetHandler</a></div><div class="ttdeci">int32_t IRQ_SetHandler(IRQn_ID_t irqn, IRQHandler_t handler)</div><div class="ttdoc">Register interrupt handler.</div></div>
<div class="ttc" id="agroup__irq__priority__defs_html_gabaa4e91ab84dbe5f669080af6d0d81fa"><div class="ttname"><a href="group__irq__priority__defs.html#gabaa4e91ab84dbe5f669080af6d0d81fa">IRQ_PRIORITY_Msk</a></div><div class="ttdeci">#define IRQ_PRIORITY_Msk</div><div class="ttdoc">Interrupt priority value bit-mask.</div></div>
<div class="ttc" id="agroup__system__init__gr_html_gaa3cd3e43291e81e795d642b79b6088e6"><div class="ttname"><a href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a></div><div class="ttdeci">uint32_t SystemCoreClock</div><div class="ttdoc">Variable to hold the system core clock value.</div><div class="ttdef"><b>Definition:</b> ref_system_init.txt:67</div></div>
<div class="ttc" id="airq__ctrl_8h_html_ac62964c04a7fed2c84aeea9e34f415e2"><div class="ttname"><a href="irq__ctrl_8h.html#ac62964c04a7fed2c84aeea9e34f415e2">IRQn_ID_t</a></div><div class="ttdeci">int32_t IRQn_ID_t</div><div class="ttdoc">Interrupt ID number data type.</div><div class="ttdef"><b>Definition:</b> irq_ctrl.h:43</div></div>
</div><!-- fragment --><h1><a class="anchor" id="using_ARM_pg"></a>
Using CMSIS with generic Arm Processors</h1>
<p>The <a href="https://github.com/ARM-software/Cortex_DFP">Cortex_DFP pack</a> provides generic device definitions for standard Arm Cortex-A cores and contains corresponding. These generic Arm devices can be used as a target for embedded programs, with execution, for example, on processor simulation models. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">
      <script type="text/javascript">
        <!--
        writeFooter.call(this);
        //-->
      </script> 
    </li>
  </ul>
</div>
</body>
</html>
